package com.lanou.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lanou.pojo.PaymentTempEntity;
import com.lanou.service.TemporayService;
import com.lanou.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "临时收费管理",tags = "收银")
public class TemporayController {
    @Resource
    private TemporayService temporayService;
    @ApiOperation(value = "获取临时收费数据",httpMethod = "GET")
    @RequestMapping(value = "/selectTemporayChargesList",produces ="text/html;charset=utf-8")
    public String  selectTemporayChargesList(String pageNum , String pageSize, String resourceName, String feeUser, String state, String feeItemName, String payType){
        List<PaymentTempEntity> paymentTempEntities = temporayService.selectTemporayChargesList(pageNum, pageSize, resourceName, feeUser, state, feeItemName, payType);

        PageInfo info = new PageInfo<>(paymentTempEntities);

        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(info);

        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "添加临时收费数据",httpMethod = "GET")
    @RequestMapping("/addPaymentTempdata")
    public void addPaymentTemp( @RequestBody Map<String,String> requestbody) throws ParseException {
        String id = requestbody.get("id");
        String name = requestbody.get("name");
        String chargeitem = requestbody.get("chargeitem");
        String paymethod = requestbody.get("paymethod");
        String money = requestbody.get("money");
        String date1 = requestbody.get("date1");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = dateFormat.parse(date1);
        System.out.println(requestbody);
        temporayService.addPaymentTemp(id,name,chargeitem,paymethod,money,date);
    }
    @ApiOperation(value = "更新收费数据",httpMethod = "GET")
    @RequestMapping("/updateByPaymentTemp")
    @ResponseBody
    public void updateByid(@RequestBody Map<String,String> requestbody) throws ParseException {
        String remark = requestbody.get("remark");
        String refundType = requestbody.get("refundType");
        String id = requestbody.get("id");
        String time = requestbody.get("refundTime");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date refundTime = dateFormat.parse(time);
        temporayService.updateByid(refundTime,remark,refundType,id);

    }

}
